<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>NCC问候语</title>
		<link rel="stylesheet" href="../../lib/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../static/css/font.css">
		<link rel="stylesheet" href="../../static/css/weadmin.css">
		<style>
			select{
				width: 150px;
				color: #666;
				height: 38px;
			    line-height: 1.3;
			    border:1px solid #e6e6e6;
			    background-color: #fff;
			    border-radius: 2px;
			    padding-left: 5px;
			}
		</style>
	</head>

	<body>
		<div class="weadmin-nav">
			<span class="layui-breadcrumb" style="visibility: visible;">
		        <a href="">NCC管理</a>
		        <a>
	          		<cite>问候语列表</cite>
		        </a>
	      	</span>
			<a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
				<i class="layui-icon" style="line-height:30px">ဂ</i>
			</a>
		</div>
		<div class="wrap">
			<blockquote class="layui-elem-quote news_search">
				<div class="layui-inline">
					<a id="" class="layui-btn layui-btn-normal" onclick="WeAdminShow('问候语KPI','./greet-add.html')">添加</a>
				</div>
				<div style="margin-left:30px;" class="layui-inline" >
					<select id="brand" onchange="selectChange()" style="width:100px;" class="valid">
						<option value="-1">品牌(全部)</option>
						<option value="CPB">CPB</option>
						<option value="SHISEIDO">SHISEIDO</option>
						<option value="IPSA">IPSA</option>
					</select>
				</div>
				
				<div style="margin-left:30px;" class="layui-inline" >
					<select id="campaign_type" onchange="selectChange()" style="width:100px;" class="valid">
						<option value="-1">活动(全部)</option>
						<option value="nutm27">nutm第一波</option>
						<option value="nutm55">nutm第二波</option>
						<option value="utm27">utm第一波</option>
						<option value="utm55">utm第二波</option>
					</select>
				</div>
				
			</blockquote>
			<!--  活动列表表格 -->
			<table class="layui-table" lay-filter="greet_table" id="greet_table" style="margin: 0"></table>
		</div>
		<script src="../../publicjs/jquery-1.8.0.min.js"></script>
		<script src="../../lib/layui/layui.js"></script>
		<script src="../../static/js/admin.js" charset="utf-8"></script>
		<script src="../../publicjs/smallkingutil.js"></script>
		<script>
			layui.use('table', function() {
				var table = layui.table;
				// 加载门店数据表格
				window.greetTable = table.render({
					id: 'greetTable',
					elem: '#greet_table',
					url: commonUtil.domain() +'/admin/wxwork/ncc/greet/list?type=1', // 数据接口
					page: true, // 开启分页
					request: {
						pageName: 'pageNum', // 分页当前页数发给后台的参数名
						limitName: 'pageSize' // 分页每页多少条发给后台的参数名
					},
					done:function(res){
						$('.layui-laypage-count').text('共'+res.total+'条')
					},
					cols: [
						[ //表头
							{
								field: 'brand',
								title: '所属品牌',
								width: 100
							},{
								field: 'campaign',
								title: '所属活动',
								width: 120,
								templet : "#campaign"
							},{
								field: 'greet',
								title: '具体内容',
								width: 500
							},{
								field: 'createTime',
								title: '创建时间',
								width: 110
							},{
								field: 'oper',
								title : '操作',
								width : 70,
								templet : "#oper"
							}
						]
					]
				});
				// 刷新表格
				greetTable.refresh = function(data) {
					greetTable.reload({
						where: data,
						page: {
							curr: 1 //重新从第 1 页开始
						}
					});
				}
				// 下拉框变更事件
				window.selectChange = function(){
					var brand = $('#brand option:selected').val();
					var campaign = $('#campaign_type option:selected').val();
					var type = $('#greet_type option:selected').val();
					var data = {};
					if(brand != -1){
						data.brand = brand;
					}
					if(campaign != -1){
						data.campaign = campaign;
					}
					if(type != -1){
						data.type = type;
					}
					greetTable.refresh(data);
				}
				// 监听表格事件
				table.on('tool(greet_table)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
					  var data = obj.data; // 获得当前行数据
					  console.info("data:",data);
					  var id = data.id;
					  var layEvent = obj.event; // 获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
					  var tr = obj.tr; // 获得当前行 tr 的DOM对象
					  if(layEvent === 'update'){
							WeAdminShow('修改问候语', 'greet-add.html?id=' + id);
					  }else if(layEvent == 'delete'){
						  layer.confirm('确认要删除此问候语吗？', function(index) {
								// 删除用户
								var ajaxParam = {
									url: commonUtil.domain() + '/admin/wxwork/ncc/greet/delete',
									data: {
										id: id
									}
								}
								ajaxUtil.post(ajaxParam, function(data) {
									if(data.code == 200) {
										layer.alert("删除成功", {
											icon: 6
										}, function() {
											greetTable.refresh();
											layer.closeAll();
										});
									} else {
										layer.alert(data.msg);
									}
								});
							});
					  }
				});
			});
		</script>
		<script type="text/html" id="campaign">
  			{{# if(d.campaign == 'nutm27'){ }}
			nutm第一波{{# } else if(d.campaign == 'nutm55'){ }}
			nutm第二波 {{# } else if(d.campaign == 'utm27'){ }}
			utm第一波 {{# } else if(d.campaign == 'utm55'){ }}
			utm第二波
			{{# } }}
		</script>
		<script type="text/html" id="type">
  			{{# if(d.type == 1){ }}
			<span class="layui-btn layui-btn-normal layui-btn-xs">默认</span> {{# } else { }}
			<span class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled">个人</span> {{# } }}
		</script>
		<script type="text/html" id="edit">
			{{# if(d.editable == 1){ }}
			<span class="layui-btn layui-btn-normal layui-btn-xs">是</span> {{# } else { }}
			<span class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled">否</span> {{# } }}
		</script>
		<script type="text/html" id="oper">
              <a title="修改" lay-event="update"><i class="layui-icon">&#xe642;</i></a>            
              <a title="删除" lay-event="delete"><i class="layui-icon">&#xe640;</i></a>
		</script>
	</body>

</html>